#ifndef __REDSTONE_REPEATER_H__
#define __REDSTONE_REPEATER_H__

#include "redstone.h"

#define RP_LED_ON           0
#define RP_LED_OFF          1

#define RP_OUT_ON           1
#define RP_OUT_OFF          0

#define RP_GEAR_SELECTED    0
#define RP_GEAR_UNSELECTED  0

typedef enum {
    RP_PIN_OUTPUT_LED = 0,
    RP_PIN_OUTPUT,
    RP_PIN_LATCH_LED,

    RP_PIN_GEAR1,
    RP_PIN_GEAR2,
    RP_PIN_GEAR3,
    RP_PIN_GEAR4,

    RP_PIN_NUM,
} REPEATER_PIN_E;

typedef enum {
    RP_GEAR_1 = 1,
    RP_GEAR_2 = 2,
    RP_GEAR_3 = 3,
    RP_GEAR_4 = 4,
    RP_GEAR_UNKNOWN = RP_GEAR_4,
} REPEATER_GEAR_E;

struct redstone_repeater_stu {
    struct redstone_stu rs_back;
    struct redstone_stu rs_left;
    struct redstone_stu rs_right;

    uint8_t last_gear;

    struct {
        GPIO_TypeDef  *port;
        uint16_t pin;
    } pin_list[RP_PIN_NUM];

    int (*pin_init)(struct redstone_repeater_stu *repeater);
    void (*write_pin)(struct redstone_repeater_stu *repeater, REPEATER_PIN_E pin, uint8_t state);
    uint8_t (*read_pin)(struct redstone_repeater_stu *repeater, REPEATER_PIN_E pin);
};

int RS_repeater_init(struct redstone_repeater_stu *repeater);
REPEATER_GEAR_E RS_repeater_get_gear(struct redstone_repeater_stu *repeater);


uint16_t myRS_get_mv_back(struct redstone_stu *rs);
uint16_t myRS_get_mv_left(struct redstone_stu *rs);
uint16_t myRS_get_mv_right(struct redstone_stu *rs);


int myRP_pin_init(struct redstone_repeater_stu *repeater);
void myRP_write_pin(struct redstone_repeater_stu *repeater, REPEATER_PIN_E pin, uint8_t state);
uint8_t myRP_read_pin(struct redstone_repeater_stu *repeater, REPEATER_PIN_E pin);

#endif // __REDSTONE_REPEATER_H__
